﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace Fast.Extensions.Caching
{
    /// <summary>
    /// 
    /// </summary>
    public class DistributedCacheKeyNormalizer : IDistributedCacheKeyNormalizer, ITransientDependency
    {
        //应当考虑多租户的问题
        //protected ICurrentTenant CurrentTenant { get; }

        protected FastDistributedCacheOptions DistributedCacheOptions { get; }

        public DistributedCacheKeyNormalizer(IOptions<FastDistributedCacheOptions> distributedCacheOptions)
        {
            DistributedCacheOptions = distributedCacheOptions.Value;
        }
        public virtual string NormalizeKey(DistributedCacheKeyNormalizeArgs args)
        {
            var normalizedKey = $"{args.CacheName}:{DistributedCacheOptions.KeyPrefix}{args.Key}";

            //if (!args.IgnoreMultiTenancy && CurrentTenant.Id.HasValue)
            //{
            //    normalizedKey = $"t:{CurrentTenant.Id.Value},{normalizedKey}";
            //}

            return normalizedKey;
        }
    }
}
